package com.lanswon.qzsmk.controller.inventoryManageController;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.qzsmk.annotation.SystemControllerLog;
import com.lanswon.qzsmk.model.StockSum;
import com.lanswon.qzsmk.service.systemManageService.InventoryManagementService;

import ch.qos.logback.classic.Logger;

@Controller
@RequestMapping(value = "/inventoryQueryOfAmountAtBranch")
public class InventoryQueryOfAmountAtBranchController {
	private final static Logger logger = (Logger) LoggerFactory.getLogger(InventoryQueryOfAmountAtBranchController.class);
	
	@Autowired
	InventoryManagementService ims;
	
	@RequiresPermissions("inventoryQueryOfAmountAtBranch:index")
	@RequestMapping(name = "库存查询画面,inventoryQueryOfAmountAtBranch:index",value = "/queryInventory", method = RequestMethod.GET)
	@SystemControllerLog(description = "跳转出库撤销页面")
	public String queryInventory(HttpServletRequest request) {

		return "QueryInventory";
	}
	
	
	@RequiresPermissions("inventoryQueryOfAmountAtBranch:getInventoryInfo")
	@RequestMapping(name = "库存查询,inventoryQueryOfAmountAtBranch:getInventoryInfo",value = "/getInventoryInfo", method = RequestMethod.POST)
	@ResponseBody
	@SystemControllerLog(description = "查询库存")
	public Map<String,Object> getInventoryInfo(HttpServletRequest request) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		List<StockSum> stockSumList = ims.queryStockSum(request);
		resultMap.put("list", stockSumList);
		return resultMap;
	}
	
	@RequestMapping(value = "/queryDetailInvCardInfo", method = RequestMethod.GET)
	@SystemControllerLog(description = "跳转出库撤销页面")
	public String queryDetailInvCardInfo(HttpServletRequest request) throws UnsupportedEncodingException {
		Map<String,Object> stockDetailMap = ims.queryStockDetailCardInfo(request);
		request.getSession().removeAttribute("stockDetailMap");
		request.getSession().setAttribute("stockDetailMap", stockDetailMap);
		return "StockDetailWithCardInfo";
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getDetailInvCardInfo", method = RequestMethod.GET)
	@ResponseBody
	@SystemControllerLog(description = "跳转出库撤销页面")
	public Map<String,Object> getDetailInvCardInfo(HttpServletRequest request) {
		Map<String,Object> stockDetailMap = new HashMap<String,Object>();
		stockDetailMap = (Map<String, Object>) request.getSession().getAttribute("stockDetailMap");
		return stockDetailMap;
	}
	
}
